const http = require('http')
const queryString = require('querystring')
const fs = require('fs')
const urlLib = require('url')


let server = http.createServer(function(req,res){
	let getjson = urlLib.parse(req.url,true)
	let url = getjson.pathname
	const GET = getjson.query
	console.log(GET)

	let str = ''
	req.on('data',function(data){
		str += data
	})
	req.on('end',function(){
		const POST = queryString.parse(str)
		console.log(POST)
	})
	let file_name = './www' + url
	fs.readFile(file_name,function(err,data){
		if(err){
			res.write('404')
		}else{
			res.write(data)
		}
		res.end()
	})

})
server.listen(8080)